#ifndef _mpeg4_avc_h_
#define _mpeg4_avc_h_

#include <stdint.h>
#include <stddef.h>

#if defined(__cplusplus)
extern "C" {
#endif
/* 一帧图像的 AVC 数据*/
struct mpeg4_avc_t
{
	uint8_t profile;    // 主要就是画质 profile_idc 基准档次：66 主要档次：77   扩展档次：88  这个是SPS中的第一个字节所标注的
	uint8_t compatibility; // constraint_set[0-5]_flag
	uint8_t level;    // Level定义了某种条件下的最大视频分辨率、最大视频帧率等参数
	uint8_t nalu; // NAL单元的长度 = (lengthSizeMinusOne + 1), default 4(0x03+1)

	uint8_t nb_sps;   /* 最大为32*/
	uint8_t nb_pps;   

	struct mpeg4_avc_sps_t
	{
		uint16_t bytes; // 大小
		uint8_t* data;  // 数据
	}  sps[32];

	struct mpeg4_avc_pps_t
	{
		uint16_t bytes;
		uint8_t* data;
	} pps[256];

	// extension
	uint8_t chroma_format_idc;
	uint8_t bit_depth_luma_minus8;
	uint8_t bit_depth_chroma_minus8;

    uint8_t data[4 * 1024];
	size_t off;
};





int mpeg4_avc_decoder_configuration_record_load(const uint8_t* data, size_t bytes, struct mpeg4_avc_t* avc);

int mpeg4_avc_decoder_configuration_record_save(const struct mpeg4_avc_t* avc, uint8_t* data, size_t bytes);

int mpeg4_avc_to_nalu(const struct mpeg4_avc_t* avc, uint8_t* data, size_t bytes);

int mpeg4_avc_codecs(const struct mpeg4_avc_t* avc, char* codecs, size_t bytes);

int h264_annexbtomp4(struct mpeg4_avc_t* avc, const void* data, size_t bytes, void* out, size_t size, int* vcl, int* update);

int h264_mp4toannexb(const struct mpeg4_avc_t* avc, const void* data, size_t bytes, void* out, size_t size);

int h264_is_new_access_unit(const uint8_t* nalu, size_t bytes);

int mpeg4_h264_annexb_nalu(const void* h264, size_t bytes, void (*handler)(void* param, const uint8_t* nalu, size_t bytes), void* param);

int mpeg4_h264_bitstream_format(const uint8_t* h264, size_t bytes);

#if defined(__cplusplus)
}
#endif
















#endif